﻿#include "GUIWidgetBase.h"

#include "OperatorsInterface/GraphEventOperator.h"
#include "PostGraphAdaptor/PostGraphObjectBase.h"
#include "PostGraphAdaptor/PostGraphProperty.h"
#include "PostGraphAdaptor/PostGraphObjectManager.h"

#include "FITK_Interface/FITKInterfaceCFDPost/FITKAbstractCFDPostData.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPost3DManager.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPostData.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"

#include "GUIFrame/MainWindow.h"
#include "GUIFrame/RenderWidget.h"
#include "FITK_Component/FITKRenderWindowVTK/FITKGraph3DWindowVTK.h"
//#include "FITK_Component/FITKRenderWindowVTK/FITKGraphRender.h"
#include "FITK_Component/FITKWidget/FITKMdiArea.h"

namespace GUI {
    GUIWidgetBase::GUIWidgetBase(QWidget * parent) :
        Core::FITKWidget(parent) {
        _mainWin = dynamic_cast<GUI::MainWindow*>(FITKAPP->getGlobalData()->getMainWindow());
        _postDataManager = FITKAPP->getGlobalData()->getPostData<Interface::FITKCFDPostData>()->getPostDataManager();
        _postLightManager = FITKAPP->getGlobalData()->getPostData<Interface::FITKCFDPostData>()->getPostLightManager();
        _postGraphManager = Interface::PostGraphObjectManager::getInstance();
    }

    GUIWidgetBase::~GUIWidgetBase() {

    }

    void GUIWidgetBase::reRender() {
        EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("OperGraphPreprocess");
        if (graphOper == nullptr) {
            return;
        }
        graphOper->reRender();
    }

    Comp::FITKGraph3DWindowVTK * GUIWidgetBase::getGraphWidget() {
        GUI::RenderWidget* renderWidget = _mainWin->getRenderWidget();
        if (renderWidget == nullptr) {
            return nullptr;
        }
        Comp::FITKMdiArea* midArea = renderWidget->getMdiArea();
        if (midArea == nullptr) {
            return nullptr;
        }
        Comp::FITKGraph3DWindowVTK* graph3DWidget = dynamic_cast<Comp::FITKGraph3DWindowVTK*>(midArea->getCurrentWidget());
        return graph3DWidget;
    }
}

